clear all
close all
lambda = 2i;

omega =  (1+i)/sqrt(2);
omega = 0
%q=1.3;

a = abs(lambda)^2;
b = real(lambda^2);
c = abs(omega)^2;
%f=inline(['(x^2+y^2)^2-(1-' num2str(c) ')*(x^2-y^2)^2- 2*' num2str(a-(1-c)*b) '*(x^2-y^2)+' num2str(a^2-4*a*imag(lambda)^2 - (1-c) * b^2) ''  ],'x','y');
%f= inline(['(x^2+y^2)^2-' num2str(a^2) ' -2*' num2str(a) '*(x^2-y^2-' num2str(b) ' ) - (1-' num2str(c) ')*(x^2-y^2-' num2str(b) ' )^2'],'x','y')
% f=inline(['(x^2+y^2)^2-2*' num2str(b) '*(x^2-y^2) +' num2str(b^2-4*imag(lambda)^2*q+4*real(lambda)^2*imag(lambda)^2 ) ''],'x','y');
f1 = inline(['x^2-y^2-' num2str(b) ''],'x','y'); % ok
f = inline(['x^2+y^2-' num2str(a) ''],'x','y'); % ok
% f2 = inline(['-4*x^2*y^2 +4*' num2str(imag(lambda)^4+10) '+4*(x^2-y^2) *' num2str(imag(lambda)^2) ''],'x','y');
%f3 = inline([' (x^2-y^2 -' num2str(b) ')^2-(x^2+y^2)^2+' num2str(a^2) '+2*(x^2-y^2-' num2str(b) ')*' num2str(a) '-' num2str(q12^2) ''])%diskriminant
rangexy = [-6 6 -6 6];
N=2000;

scrsz = get(0,'ScreenSize');
fig = figure('Position',[1 450 450 450]);
clf
[x,y,fvalues] = implot(f,rangexy,N,'b');

hold on;
[x1,y1,fvalues]= implot(f1,rangexy,N,'b');

%[X0,Y0] = intersections(x,y,x1,y1,1);

indexy = find(x<0);
x = x(indexy);
y = y(indexy);

indexy1 = find(x1<0);
x1 = x1(indexy1);
y1 = y1(indexy1);


%indexy = find(X0<0);
indexy_hyp_velke= find(y1 >= imag(lambda));
indexy_hyp_male = find(y1 <= -imag(lambda));
indexy_toricu = find(y <= imag(lambda));
vtx = x(indexy_toricu);
vty = y(indexy_toricu);
indexy_toricu = find(vty >= -imag(lambda));
vtx = vtx(indexy_toricu);
vty = vty(indexy_toricu);


xv = [x1(indexy_hyp_male) x1(indexy_hyp_velke)  vtx];
yv = [y1(indexy_hyp_male) y1(indexy_hyp_velke) vty];
xy = [xv; yv];
tt = sortrows(xy',2)';
%tt = tt(:,1:end-1);
%tt = sortrows(tt',1)';
%h =
fill([  tt(1,1:end) ], tt(2,1:end) ,[0.75 0.75 0.75],'LineWidth',0.001,'LineStyle','none')
%alpha(h,0.4);
%alphable = findobj(h, '-property', 'FaceAlpha');
%set(alphable, 'FaceAlpha', 0.5);
%plot(x_imag,y_imag,'r-','LineWidth',2);
% plot(real(lambda),imag(lambda),'k+','Markersize',10,'LineWidth',1)
plot([min(abs(rangexy)) -min(abs(rangexy))],[min(abs(rangexy)) -min(abs(rangexy))],'k--','LineWidth',1);
%plot(linspace(rangexy(1),rangexy(2),N),-repmat(imag(lambda),1,N),'r-','LineWidth',2);
plot([-min(abs(rangexy)) min(abs(rangexy))],[min(abs(rangexy)) -min(abs(rangexy))],'k--','LineWidth',1)


arrow([0 0],[real(lambda) imag(lambda)])
arrow([0 0],[real(lambda) -imag(lambda)])
arrow([0 rangexy(3)],[0 rangexy(4)],'LineStyle','-','BaseAngle',45)
arrow([ rangexy(1) 0],[ rangexy(2) 0],'LineStyle','-','BaseAngle',45)
% return



implot(f,rangexy,N,'b');

implot(f1,rangexy,N,'b');

%plot(rangexy(1:2),[0 0],'k--');
%plot([0 0],rangexy(3:4),'k--');
arrow([0 rangexy(3)],[0 rangexy(4)],'LineStyle','--','BaseAngle',45)
arrow([ rangexy(1) 0],[ rangexy(2) 0],'LineStyle','--','BaseAngle',45)
arrow([0 0],[real(lambda) imag(lambda)])
arrow([0 0],[real(lambda) -imag(lambda)])


h = text;
set(h, 'interpreter', 'latex')
if real(lambda)==-1
    text([real(lambda)],[ -imag(lambda)-.5],'$\overline{\lambda}$','interpreter','latex','FontSize',16);
    text([real(lambda)],[ imag(lambda)+.5],'$\lambda$','interpreter','latex','FontSize',16)
elseif real(lambda)==-2
    text([real(lambda)-.25],[ -imag(lambda)-.75],'$\overline{\lambda}$','interpreter','latex','FontSize',16);
    text([real(lambda)-.25],[ imag(lambda)+.75],'$\lambda$','interpreter','latex','FontSize',16)
elseif real(lambda)==3
    text([real(lambda)+.5],[ -imag(lambda)],'$\overline{\lambda}$','interpreter','latex','FontSize',16);
    text([real(lambda)+.5],[ imag(lambda)],'$\lambda$','interpreter','latex','FontSize',16)

else
    text([real(lambda)+.1],[ -imag(lambda)-.5],'$\overline{\lambda}$','interpreter','latex','FontSize',16);
    text([real(lambda)+0.1],[ imag(lambda)+.5],'$\lambda$','interpreter','latex','FontSize',16)
end
text(rangexy(2)-1.25,.5,'R e$s$','interpreter','latex','FontSize',16)
text(.25,rangexy(4)-.5,'$\mbox{Im}s$','interpreter','latex','FontSize',16)
box off
axis off
%saveas(fig,['w_1' num2str(lambda) '.eps']) 

% grid on
%legend('rovnice 3','rovnice4','rovnice 2','pol','rovnice 1')
